<script>
	export default {
		globalData: {
			statusBarHeight: '', //状态栏高度
			navHeight: '', //文本内容高度
			code: '',
		},
		onLaunch: function() {
			let that = this
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			uni.getSystemInfo({
				success(res) {
					let statusBarHeight = res.statusBarHeight
					let navHeight =
						menuButtonInfo.height + (menuButtonInfo.top - statusBarHeight) * 2
					//胶囊在页面中的位置-状态栏高度得到的间距*2 再加上胶囊的高度
					that.globalData.statusBarHeight = statusBarHeight
					that.globalData.navHeight = navHeight
				},
			})
			this.checkToken()
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 如果有token,则验证token有效期
			// token有效则跳转首页免登录
			checkToken() {
				let token = uni.getStorageSync('token')
				if (token) {
					this.$api
						.checkLogin({})
						.then(res => {
							if (res.code == 200) {
								uni.switchTab({ url: '/pages/index/index' })
							} else {}
						})
				}
			}
		},
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	/* 公共样式 */
	@import "/common/css/common.css";
</style>